package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.service.MarketKeywordCRUDService;
import com.cskaoyan.market.db.domain.MarketKeyword;
import com.cskaoyan.market.db.domain.MarketKeywordExample;
import com.cskaoyan.market.db.mapper.MarketKeywordMapper;
import com.cskaoyan.market.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author TangHonghao
 * @since 2023/03/22 15:06
 */
public class MarketKeywordCRUDServiceImpl implements MarketKeywordCRUDService  {
    @Override
    public List<MarketKeyword> selectAll() {
        SqlSession session = MyBatisUtil.getSession();
        MarketKeywordMapper keywordMapper = session.getMapper(MarketKeywordMapper.class);
        MarketKeywordExample marketKeywordExample = new MarketKeywordExample();
        List<MarketKeyword> marketKeywords = keywordMapper.selectByExample(marketKeywordExample);
        return marketKeywords;
    }

    @Override
    public List<MarketKeyword> selectByKeyword(String keyword) {
        SqlSession session = MyBatisUtil.getSession();
        MarketKeywordMapper keywordMapper = session.getMapper(MarketKeywordMapper.class);
        MarketKeywordExample marketKeywordExample = new MarketKeywordExample();
        marketKeywordExample.or().andKeywordLike("%"+keyword+"%");
        List<MarketKeyword> marketKeywords = keywordMapper.selectByExample(marketKeywordExample);
        return marketKeywords;
    }
}
